﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="AdminRole.aspx.cs" Inherits="TravelLink.WebApp.Admin.AdminRole" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPopupControl" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxTreeView" tagprefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
    .style1
    {
        width: 100%;
    }
        .style2
        {
            width: 300px;
        }
    </style>
<script language="javascript">
    var rid;
    function setCheckBox(values) {
        if (typeof (tvfunc) != "undefined") {
            var count = tvfunc.GetNodeCount();
            for (var i = 0; i < count; i++) {
                var node = tvfunc.GetNode(i);
                var funccount = node.GetNodeCount();
                for (var j = 0; j < funccount; j++) {
                    var funcnode = node.GetNode(j);
                    funcnode.SetChecked(values.indexOf(funcnode.name)>-1);
                }
            }
            poppriv.Show();
        }
    }

    function showcheckbox() {
        agvrole.GetRowValues(rid, 'PrivilegeStr', setCheckBox);
    }

    function CallServer()
{
var str="";
 var count = tvfunc.GetNodeCount();
            for (var i = 0; i < count; i++) {
                var node = tvfunc.GetNode(i);
                var funccount = node.GetNodeCount();
                for (var j = 0; j < funccount; j++) {
                    var funcnode = node.GetNode(j);
                    if(funcnode.GetChecked())
                    {
                    if(str!="")
                    {
                    str+=",";
                    }
                    str+=funcnode.name;
                    }
                }
            }
var rowid =rid+";"+ agvrole.GetRowKey(rid)+";"+str;
<%= ClientScript.GetCallbackEventReference(this, "rowid", "ReceiveServerData",null)%>;
}
 
function ReceiveServerData(rValue)
{
    if(rValue=='')
    {
 	poppriv.Hide();
    alert('修改成功');
    agvrole.Refresh();
    }
    else
    {
    alert(rValue);
    }
}

function allchecked()
{
 var count = tvfunc.GetNodeCount();
            for (var i = 0; i < count; i++) {
                var node = tvfunc.GetNode(i);
                var funccount = node.GetNodeCount();
                for (var j = 0; j < funccount; j++) {
                    var funcnode = node.GetNode(j);
                    funcnode.SetChecked(true);
                }
            }
}

function rchecked()
{
 var count = tvfunc.GetNodeCount();
            for (var i = 0; i < count; i++) {
                var node = tvfunc.GetNode(i);
                var funccount = node.GetNodeCount();
                for (var j = 0; j < funccount; j++) {
                    var funcnode = node.GetNode(j);
                    funcnode.SetChecked(!funcnode.GetChecked());
                }
            }
}

function allclear()
{
 var count = tvfunc.GetNodeCount();
            for (var i = 0; i < count; i++) {
                var node = tvfunc.GetNode(i);
                var funccount = node.GetNodeCount();
                for (var j = 0; j < funccount; j++) {
                    var funcnode = node.GetNode(j);
                    funcnode.SetChecked(false);
                }
            }
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table class="style1">
        <tr>
            <td>
                <dx:ASPxButton ID="ASPxButton4" runat="server" AutoPostBack="False" Text="新增">
                    <ClientSideEvents Click="function(s, e) {
	agvrole.AddNewRow();
}" />
                </dx:ASPxButton>
            </td>
        </tr>
    </table>
    <table class="style1">
    <tr>
        <td>
            <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
                DataSourceID="ldsRole" KeyFieldName="Idx" 
                onfocusedrowchanged="ASPxGridView1_FocusedRowChanged" 
                ClientInstanceName="agvrole">
                <ClientSideEvents FocusedRowChanged="function(s, e) {

}" CustomButtonClick="function(s, e) {
	    rid=e.visibleIndex;
		showcheckbox();
}" />
                <Columns>
                    <dx:GridViewCommandColumn ButtonType="Button" Caption="操作" VisibleIndex="4">
                        <EditButton Text="修改" Visible="True">
                        </EditButton>
                        <NewButton Text="新增">
                        </NewButton>
                        <DeleteButton Text="删除" Visible="True">
                        </DeleteButton>
                        <CancelButton Text="取消" Visible="True">
                        </CancelButton>
                        <UpdateButton Text="保存" Visible="True">
                        </UpdateButton>
                        <ClearFilterButton Visible="True">
                        </ClearFilterButton>
                        <CustomButtons>
                            <dx:GridViewCommandColumnCustomButton ID="priv" Text="权限设置">
                            </dx:GridViewCommandColumnCustomButton>
                        </CustomButtons>
                    </dx:GridViewCommandColumn>
                    <dx:GridViewDataTextColumn Caption="编号" FieldName="Idx" ReadOnly="True" 
                        Visible="False" VisibleIndex="0" Width="60px">
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn Caption="名称" FieldName="Name" VisibleIndex="1" 
                        Width="120px">
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn FieldName="PrivilegeStr" Visible="False" 
                        VisibleIndex="2">
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn Caption="序号" FieldName="Seq" VisibleIndex="3" 
                        Width="80px">
                    </dx:GridViewDataTextColumn>
                </Columns>
                <Settings ShowFilterRow="True" />
            </dx:ASPxGridView>
            <dx:ASPxPopupControl ID="ASPxPopupControl1" runat="server" 
                ClientInstanceName="poppriv" EnableClientSideAPI="True" HeaderText="权限设置" PopupHorizontalAlign="WindowCenter" 
                PopupVerticalAlign="WindowCenter" Modal="True">
                <ContentCollection>
<dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
    <table class="style2">
        <tr>
            <td>
                <table class="style1">
                    <tr>
                        <td>
                            <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="全选" 
                                Width="60px">
                                <ClientSideEvents Click="function(s, e) {
	allchecked();
}" />
                            </dx:ASPxButton>
                        </td>
                        <td>
                            <dx:ASPxButton ID="ASPxButton2" runat="server" AutoPostBack="False" Text="反选" 
                                Width="60px">
                                <ClientSideEvents Click="function(s, e) {
	rchecked();
}" />
                            </dx:ASPxButton>
                        </td>
                        <td>
                            <dx:ASPxButton ID="ASPxButton3" runat="server" AutoPostBack="False" Text="全清" 
                                Width="60px">
                                <ClientSideEvents Click="function(s, e) {
	allclear();
}" />
                            </dx:ASPxButton>
                        </td>
                        <td>
                            <dx:ASPxButton ID="abtnSave" runat="server" Text="保存" AutoPostBack="False" 
                                Width="100px">
                                <ClientSideEvents Click="function(s, e) {
	CallServer();
}" />
                            </dx:ASPxButton>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <dx:ASPxTreeView ID="ASPxTreeView1" runat="server" AllowCheckNodes="True" 
                    ClientInstanceName="tvfunc" ShowTreeLines="False">
                </dx:ASPxTreeView>
            </td>
        </tr>
    </table>
                    </dx:PopupControlContentControl>
</ContentCollection>
            </dx:ASPxPopupControl>
            <asp:LinqDataSource ID="ldsRole" runat="server" 
                ContextTypeName="TravelLink.DAL.TravelLinkDBDataContext" EnableDelete="True" 
                EnableInsert="True" EnableUpdate="True" EnableViewState="False" 
                EntityTypeName="" oninserting="ldsRole_Inserting" OrderBy="Seq" 
                TableName="TL_Role">
            </asp:LinqDataSource>
        </td>
        <td>
            &nbsp;</td>
    </tr>
</table>
</asp:Content>
